<style>
    .control-label span {
        color: red;
    }
</style>

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                错误报告
            </header>
            <div class="panel-body">
                <form class="form-horizontal tasi-form layui-form">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">电子邮箱<span>*</span></label>
                        <div class="col-sm-10">
                            <input name="Email" type="text" class="form-control" required lay-verify="required" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">报告内容<span>*</span></label>
                        <div class="col-sm-10">
                            <textarea name="Content" class="form-control"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">上传图片</label>
                        <div class="col-sm-10">
                            <div class="layui-upload">
                                <button type="button" class="btn btn-primary" id="UploadBtn">选择文件</button>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="PreviewImages"></div>
                                </blockquote>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            <button type="button" class="btn btn-primary" lay-submit lay-filter="formSubmit">立即提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </section>
    </div>
</div>

<script>
    layui.use(['form','jquery','upload'], function () {
        var form = layui.form,
            $ = layui.jquery,
            upload = layui.upload,
            FileUrls = [];

        upload.render({
            elem: '#UploadBtn'
            ,url: '/index.php/Index/Common/UploadImage' //此处配置你自己的上传接口即可
            ,multiple: true
            ,field: 'Image'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                // obj.preview(function(index, file, result){
                //     $('#PreviewImages').append('<a href="'+result+'" target="_blank"><img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" style="max-width: 128px;max-height: 128px;"></a>')
                // });
            }
            ,done: function(res){
                //上传完毕
                if (res['code'] == ErrCode_Normal) {
                    var src = res['data']['src'];
                    FileUrls.push(src);
                    $('#PreviewImages').append('<a href="'+src+'" target="_blank"><img src="'+ src +'" alt="合同电子版" class="layui-upload-img" style="max-width: 128px;margin: 10px"></a>');
                } else mb_OnMessage(res);
            }
        });

        //提交表单
        form.on('submit(formSubmit)', function (data) {
            var fields = data.field;
            fields['ImageUrls'] = JSON.stringify(FileUrls);

            global.post('/index.php/user/Error_Report/mb_Submit', fields, function (msg) {
                if (msg['code'] == ErrCode_Normal) {
                    layer.msg(msg['msg'], {
                        offset: '15px'
                        , icon: 1
                        , time: 1000
                    }, function () {
                        window.location.reload();
                    });
                } else mb_OnMessage(msg);
            });
            return false;
        });
    });
</script>